package Class.Homemade.demo0527.demo1;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 姚东名
 * Date: 2024-05-27
 * Time: 20:51
 */
/*
内部类：
1.静态内部类
2.实例内部类
3.匿名内部类
4.局部内部类
 */
class OutClass {
    public int data1 = 1;
    private int data2 = 2;
    public static int data3 = 3;
    //对于InnerClass来讲，OutClass为外部类
    //静态内部类
    static class InnerClass {
        public int data4 = 4;
        private int data5 = 5;
        public static int data6 = 6;
        //普通成员方法：
        public void test() {
            //对象的实例化
            OutClass outClass = new OutClass();

            System.out.println(outClass.data1);
            System.out.println(outClass.data2);
            System.out.println(data3);
            System.out.println(data4);
            System.out.println(data5);
            System.out.println(data6);
            System.out.println("test()方法被执行了...");

        }
    }
}
class OutClass2 {
    public int data1 = 1;
    private int data2 = 2;
    public static int data3 = 3;

    //实例内部类:
    /*
    对于实力内部类来讲，包含2个this，一个this是实例内部类自己的，一个是外部类名.this
     */
    class InnerClass2 {
        public int data1 = 10;
        public int data4 = 4;
        private int data5 = 5;
        //public static  int data6 = 6;

        public void test() {
            //对象的实例化
            OutClass2 outClass2 = new OutClass2();
            //调类中的data1
            System.out.println(outClass2.data1);//1
            //调实例类中的data1
            System.out.println("========");
            System.out.println(OutClass2.this.data1);//1
            System.out.println("========");
            System.out.println(this.data1);//10
            System.out.println("========");
            System.out.println(data2);
            System.out.println(data3);
            System.out.println(data4);
            System.out.println(data5);
            System.out.println("test()方法被执行了.....");
        }
    }
}
public class Test {
    public static void main(String[] args) {
        //如何实例化一个实例内部类对象
        //还是不能直接实例化一个实例内部类对象
        //InnerClass innerClass = new InnerClass();
        //但是可以实例化一个外部类对象：
        OutClass2 outClass2 = new OutClass2();
        OutClass2.InnerClass2 innerClass2 = outClass2.new InnerClass2();
        innerClass2.test();
    }
    public static void main1(String[] args) {
        //如何实例化一个静态内部类对象
        //不能直接实例化一个静态内部类对象，
        //InnerClass innerClass = new InnerClass();
        //要通过类名来调用
        OutClass.InnerClass innerClass = new OutClass.InnerClass();
        innerClass.test();
        //结论：静态内部类当中，不能够直接访问外部类的非静态的数据成员
    }
}
